import pytesseract
from PIL import Image

class TesseractRecognizer:
    async def recognize(self, image_path: str) -> str:
        """
        使用Tesseract识别验证码
        """
        image = Image.open(image_path)
        # 预处理图片(可以添加图像处理来提高识别率)
        text = pytesseract.image_to_string(image, config='--psm 7')
        # 清理识别结果,只保留字母和数字
        return ''.join(c for c in text if c.isalnum()) 